package com.ricervcvcer.goods.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ricervcvcer.common.util.ResultEntity;
import com.ricervcvcer.goods.service.ITbSpuService;
import com.ricervcvcer.goods.vo.GoodsCategoryBrandVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * spu表，该表描述的是一个抽象性的商品，比如 iphone8 前端控制器
 * </p>
 *
 * @author moge
 * @since 2022-01-06
 */
@RestController
@RequestMapping("/spu")
public class TbSpuController {
    @Autowired
    ITbSpuService spuService;

    @ApiOperation("添加spu到ElasticSearch")
    @GetMapping("addSpuEST")
    public ResultEntity addSpuEST () {
        spuService.addSpuEST();
        return ResultEntity.successWithoutData();
    }

    @ApiOperation("添加spu到ElasticSearch")
    @GetMapping("addSkuEST")
    public ResultEntity addSkuEST () {
        spuService.addSkuEST();
        return ResultEntity.successWithoutData();
    }

    @PostMapping("page")
    @ApiOperation("对商品进行分页查询")
    public ResultEntity page(
            @ApiParam("页码") @RequestParam Integer page,
            @ApiParam("每页条数") @RequestParam Integer rows,
            @ApiParam("商品名") @RequestParam String spuName,
            @ApiParam("是否上架") @RequestParam boolean searchSaleable){
        Page<GoodsCategoryBrandVO> pages = spuService.getSpu(spuName,page,rows,searchSaleable);
        return ResultEntity.successWithData(pages);
    }

}
